Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CMake build system support #240

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

feihong-gz
Copy link

No description provided.

Copy link
Contributor

@mrbean-bremen mrbean-bremen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this - this should actually be the default way to build Qt at least for Qt6.
It would also make sense to add workflows in the CI to build the latest Qt5 and Qt6 version, to be able to test this - for the time being probably parallel to the existing workflows using qmake.

CMakeLists.txt Outdated
endif()
# elseif(${QT_VERSION_MAJOR} VERSION_EQUAL 6)
else()
message(FATAL "No generated sources exist for Qt${QT_VERSION}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not handle the (actually preferred) case of self-generated wrappers in generated_cpp, as done in the qmake file. Especially this will not work for Qt6, unless I'm missing something.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to build generator using CMake, and so far it's testing well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mkdir build
cmake -S  src -B build --install-prefix <path-to-install>
cmake --build build --parallel --target all install

Currently compiles and installs properly. Earlier I was thinking about how to use the code generated by generator, because in the configuration phase generator is not generated yet, and in the compilation phase it's too late. So I didn't do much about this later. But I currently have some ideas on how to solve this problem.
I apologize for not replying to you until now, as I don't usually follow github. It's going to be Chinese New Year now, so I probably won't do anything until after Chinese New Year.
My English is not very good either, so I hope you can understand what I said.
Meanwhile, wish you happy Chinese New Year in advance.

Translated with DeepL.com (free version)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, take your time, and thank you for your contribution!

Happy New Year to you!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On CMake, I had to know the exact filename of the file to be generated, so I modified the file size limit. Also, this commit only executes properly on Qt5, Qt6 seems to generate some duplicates inside the source file. Maybe the generator needs some changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the current implementation may not be elegant, but it is a viable solution, subject to subsequent improvements.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@usiems is currently working on changing the preprocessor, this might resolve some issues, though I'm not sure.
If the solution is working, we can always improve it later, and if we have the CI tests in place (see my previous comment), this should be easier.

@jamesobutler
Copy link

@jcfr This may be a PR of interest to you based on your previous work from 2019 to CMake’ify PythonQt as completed in https://github.com/commontk/PythonQt/blob/patched-9/CMakeLists.txt (though currently for Qt5 PythonQt only).

@mrbean-bremen
Copy link
Contributor

@feihong-gz - I forgot about this PR... what is the state here? Is this ready to merge?

It would really be helpful to add some CI builds using CMake - for example by adding it as an extra option to the existing builds.

Something like:

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        os: ['ubuntu', 'windows']
        qt-version: [ '5.12.*', '5.15.*', '6.7.*' ]
        python-version: [ '3.12' ]
        build-tool: [qmake, cmake]  # new configuration
...

    - name: Build generator Ubuntu / qmake  # existing build
      shell: bash
      if: ${{ matrix.os == 'ubuntu' && matrix.build-tool == 'qmake' }} 
      run: |
        cd generator
        qmake -r generator.pro CONFIG+=ccache CONFIG+=release CONFIG-=debug_and_release CONFIG+=force_debug_info \
        CONFIG+=sanitizer CONFIG+=sanitize_undefined CONFIG+=sanitize_address
        make -j $(nproc)

    - name: Build generator Ubuntu / cmake  # new cmake build
      shell: bash
      if: ${{ matrix.os == 'ubuntu' && matrix.build-tool == 'cmake' }} 
      run: |
        cd generator
        cmake ...
...

@feihong-gz feihong-gz closed this Jan 17, 2025
@feihong-gz feihong-gz reopened this Jan 17, 2025
@mrbean-bremen
Copy link
Contributor

I see that you have started working on this again 👍🏼 . If you need help with the workflows, let us know - having the workflows test the build is quite important to avoid regressions and to test different OSes.

@feihong-gz
Copy link
Author

I see that you have started working on this again 👍🏼 . If you need help with the workflows, let us know - having the workflows test the build is quite important to avoid regressions and to test different OSes.

mkdir build
cmake -S  src -B build --install-prefix <path-to-install>
cmake --build build --parallel --target all install

It builds, tests, and installs automatically, and is available on Windows and GNU/Linux platforms.

@mrbean-bremen
Copy link
Contributor

It builds, tests, and installs automatically, and is available on Windows and GNU/Linux platforms.

To see this in the CI, we have to adapt the workflow files to also build using cmake, see my snippet above of how to do this.
As I also wrote above - I can help you with this is needed.

push:
branches:
- master

Copy link
Contributor

@mrbean-bremen mrbean-bremen Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to trigger on pull-request to be able to see it in the PR build.
But you probably know that...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generator seems to need some changes, the path to the fetched header file is not always correct in different environments

choco install qt6 --version ${{ matrix.qt_version }}.0.0 --params "/InstallationFolder C:/Qt/${{ matrix.qt_version }}"
echo "C:/Qt/${{ matrix.qt_version }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "QTDIR=C:/Qt/${{ matrix.qt_version }}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
}
Copy link
Contributor

@mrbean-bremen mrbean-bremen Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be easier to use use jurplel/install-qt-action like in build_latest.yml to install Qt, you may take the step from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants